Skip to contentMethod: static {...}
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * blueMarine III: Semantic DAM
5: * http://tidalwave.it/projects/bluemarine3
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/bluemarine3-src
22: * git clone https://github.com/tidalwave-it/bluemarine3-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.dam.model.io;
27:
28: import jakarta.annotation.Nonnull;
29: import java.time.ZonedDateTime;
30: import java.util.Locale;
31: import java.util.Optional;
32: import java.util.function.Predicate;
33: import java.io.IOException;
34: import java.nio.file.Path;
35: import it.tidalwave.dam.model.Entity;
36: import it.tidalwave.dam.model.MimeType;
37: import it.tidalwave.dam.model.io.impl.DefaultFileEntity;
38: import it.tidalwave.ui.core.role.Displayable;
39: import it.tidalwave.util.As;
40: import it.tidalwave.util.Finder;
41: import it.tidalwave.role.Composite;
42:
43: /***************************************************************************************************************************************************************
44: *
45: * Models a file with its attributes and children.
46: *
47: * @author Fabrizio Giudici
48: *
49: **************************************************************************************************************************************************************/
50: public interface FileEntity extends Entity, Displayable
51: {
52: /** The {@link As.Type} as a {@link Composite}. */
53: public static final As.Type<Composite<FileEntity, Finder<FileEntity>>> _FileEntityComposite_ = As.type(Composite.class);
54:
55: /***********************************************************************************************************************************************************
56: * {@return a new instance} related to the given path.
57: * @param path the path
58: **********************************************************************************************************************************************************/
59: @Nonnull
60: public static FileEntity of (@Nonnull final Path path)
61: {
62: return new DefaultFileEntity(path, ignored -> true);
63: }
64:
65: /***********************************************************************************************************************************************************
66: * {@return a new instance} related to the given path.
67: * @param path the path
68: * @param filter a predicate to filter children
69: **********************************************************************************************************************************************************/
70: public static FileEntity of (@Nonnull final Path path, @Nonnull final Predicate<FileEntity> filter)
71: {
72: return new DefaultFileEntity(path, filter);
73: }
74:
75: /***********************************************************************************************************************************************************
76: * {@return the path} of the file.
77: **********************************************************************************************************************************************************/
78: @Nonnull
79: public Path getPath();
80:
81: /***********************************************************************************************************************************************************
82: * {@return the extension} of the file.
83: **********************************************************************************************************************************************************/
84: @Nonnull
85: public default String getExtension()
86: {
87: final var string = getPath().toString();
88: return string.contains(".") ? string.replaceAll("^[^.]*\\.", "") : "";
89: }
90:
91: /***********************************************************************************************************************************************************
92: * {@return the low case extension} of the file.
93: **********************************************************************************************************************************************************/
94: @Nonnull
95: public default String getLcExtension()
96: {
97: return getExtension().toLowerCase(Locale.ROOT);
98: }
99:
100: /***********************************************************************************************************************************************************
101: * {@return the creation date-time} of the file.
102: * @throws IOException if the file does not exist or cannot be accessed
103: **********************************************************************************************************************************************************/
104: @Nonnull
105: public ZonedDateTime getCreationDateTime()
106: throws IOException;
107:
108: /***********************************************************************************************************************************************************
109: * {@return the last access date-time} of the file.
110: * @throws IOException if the file does not exist or cannot be accessed
111: **********************************************************************************************************************************************************/
112: @Nonnull
113: public ZonedDateTime getLastAccessDateTime()
114: throws IOException;
115:
116: /***********************************************************************************************************************************************************
117: * {@return the last modified date-time} of the file.
118: * @throws IOException if the file does not exist or cannot be accessed
119: **********************************************************************************************************************************************************/
120: @Nonnull
121: public ZonedDateTime getLastModifiedDateTime()
122: throws IOException;
123:
124: /***********************************************************************************************************************************************************
125: * {@return the size} of the file.
126: * @throws IOException if the file does not exist or cannot be accessed
127: **********************************************************************************************************************************************************/
128: // @Nonnegative FIXME
129: public long getSize()
130: throws IOException;
131:
132: /***********************************************************************************************************************************************************
133: * {@return the MIME type of this file}.
134: **********************************************************************************************************************************************************/
135: @Nonnull
136: public Optional<MimeType> getMimeType();
137:
138: /***********************************************************************************************************************************************************
139: * {@return {@code true} when the entity is a directory}.
140: **********************************************************************************************************************************************************/
141: boolean isDirectory();
142:
143: /***********************************************************************************************************************************************************
144: * {@return {@code true} when the entity is a UN*X hidden file} (the name starts with a '.').
145: **********************************************************************************************************************************************************/
146: public boolean isUnixHiddenFile();
147: }